// 操作状态
function actionFormatter() {
   // var del=`<button class="btn btn-danger"><i class="glyphicon glyphicon-trash "></i>删除</button>&nbsp;`;
   var edit=`<button  class="cc btn btn-warning"><i class="glyphicon glyphicon-edit "></i>编辑</button>`;
   return edit;
}
// 处理时间格式
function fmtDate(value){
    return value.substring(0,10);
}
// 查询分配状态
$.get("cus/hkzygl/list")
    .done(list=>{
        list.forEach(function (khzygl) {
            var opt= $("<option/>");
            opt.val(khzygl.fenpeiid);
            opt.text(khzygl.fenpeizhuangtai);
            opt.appendTo("#queryForm [name=fenpeiid]");
        })
    })
// 处理状态回显
$.get("cus/hkzygl/queryAll")
    .done(list=>{
        list.forEach(function (Kehustart) {
            var opt= $("<option/>");
            opt.val(Kehustart.kehuid);
            opt.text(Kehustart.kehuzhuangtai);
            opt.appendTo("#update [name=status]");
        })
    })
// 处理类型回显
$.get("cus/hkzygl/queryleixing")
    .done(list=>{
        list.forEach(function (Customertype) {
            var opt= $("<option/>");
            opt.val(Customertype.customerTypeId);
            opt.text(Customertype.customerTypeName);
            opt.appendTo("#update [name=type]");
        })
    })
// 条件查询
function chaxun() {
    var formParams=$("#queryForm").serialize();
    var obj=Qs.parse(formParams);
    $("#roleTb").bootstrapTable("refresh",{query:obj});
}
// 编辑信息数据回显
var actionEvents={
    "click .cc":function (a,b,row,index) {
            $("#update [name=customerId]").val(row.customerId);
            $("#update [name=customerDicId]").val(row.customerDicId);
            $("#update [name=birthday]").val(row.birthday);
            $("#update [name=name]").val(row.name);
            $("#update [name=type]").val(row.type);
            $("#update [name=status]").val(row.status);
            $("#update [name=cellphone]").val(row.cellphone);
            $("#update [name=officeTel]").val(row.officeTel);
            $("#update [name=email]").val(row.email);
            $("#update [name=homeTel]").val(row.homeTel);
            $("#update [name=address]").val(row.address);
            $("#update [name=feedBack]").val(row.feedBack);
            $("#update").dialog("show");
    }
}

// 弹出模态框进行修改客户信息
$("#update").dialog({
        title:"修改客户资源",
        btnBind(){
            var params=$("#update form").serialize();
            $.get(`${ctx}/cus/hkzygl/update`,params)
                .done(msg=>{
                    toastr.success(msg);
                    $("#roleTb").bootstrapTable("refresh");
                    $("#update").dialog("hide");
                })
        }
})
// ==============================================================================================
// 添加显示模态框
function add(){
    $("#add").dialog("show")
}
$("#add").dialog({
    title: "添加客户资源",
    btnBind(){
        var params=$("#add form").serialize();
        $.post(`${ctx}/cus/hkzygl/add`,params)
            .done(msg=>{
                toastr.success(msg);
                $("#roleTb").bootstrapTable("refresh");
                $("#add").dialog("hide");
            });
    }
})

// 添加处理状态回显
$.get("cus/hkzygl/queryAll")
    .done(list=>{
        list.forEach(function (Kehustart) {
            var opt= $("<option/>");
            opt.val(Kehustart.kehuid);
            opt.text(Kehustart.kehuzhuangtai);
            opt.appendTo("#add [name=status]");
        })
    })
// 添加处理类型回显
$.get("cus/hkzygl/queryleixing")
    .done(list=>{
        list.forEach(function (Customertype) {
            var opt= $("<option/>");
            opt.val(Customertype.customerTypeId);
            opt.text(Customertype.customerTypeName);
            opt.appendTo("#add [name=type]");
        })
    })
// 添加分配状态回显
$.get("cus/hkzygl/list")
    .done(list=>{
        list.forEach(function (khzygl) {
            var opt= $("<option/>");
            opt.val(khzygl.fenpeiid);
            opt.text(khzygl.fenpeizhuangtai);
            opt.appendTo("#add [name=assignmentStatus]");
        })
    })
// ==============================================================================================
// 查看详情状态回显
$.get("cus/hkzygl/queryAll")
    .done(list=>{
        list.forEach(function (Kehustart) {
            var opt= $("<option/>");
            opt.val(Kehustart.kehuid);
            opt.text(Kehustart.kehuzhuangtai);
            opt.appendTo("#cha [name=status]");
        })
    })
// 查看详情类型回显
$.get("cus/hkzygl/queryleixing")
    .done(list=>{
        list.forEach(function (Customertype) {
            var opt= $("<option/>");
            opt.val(Customertype.customerTypeId);
            opt.text(Customertype.customerTypeName);
            opt.appendTo("#cha [name=type]");
        })
    })
// 查看详情分配状态回显
$.get("cus/hkzygl/list")
    .done(list=>{
        list.forEach(function (khzygl) {
            var opt= $("<option/>");
            opt.val(khzygl.fenpeiid);
            opt.text(khzygl.fenpeizhuangtai);
            opt.appendTo("#cha [name=fenpeiid]");
        })
    })
$("#cha").dialog({
    title: "查看客户资源详情",

})
// 点击查看模态框显示
function chakan() {
    var arr= $("#roleTb").bootstrapTable("getSelections");
    if(arr.length==0) {
        swal({
            type: "warning",
            title: "信息提示！",
            text: "请选择您要查看的内容！",
            confirmButtonText: "确定"
        })
        return;
    }
    $("#cha [name=customerId]").val(arr[0].customerId);
    $("#cha [name=customerDicId]").val(arr[0].customerDicId);
    $("#cha [name=sex]").val(arr[0].sex)
    $("#cha [name=birthday]").val(arr[0].birthday);
    $("#cha [name=name]").val(arr[0].name);
    $("#cha [name=type]").val(arr[0].type);
    $("#cha [name=status]").val(arr[0].status);
    $("#cha [name=cellphone]").val(arr[0].cellphone);
    $("#cha [name=officeTel]").val(arr[0].officeTel);
    $("#cha [name=email]").val(arr[0].email);
    $("#cha [name=homeTel]").val(arr[0].homeTel);
    $("#cha [name=address]").val(arr[0].address);
    $("#cha [name=feedBack]").val(arr[0].feedBack);
    $("#cha [name=fenpeiid]").val(arr[0].assignmentStatus);
    $("#cha").dialog("show");
}

// ==============================================================================================
function piliangDel() {
    var arr= $("#roleTb").bootstrapTable("getSelections");
    if(arr.length==0) {
        swal({
            type: "error",
            title: "错误操作！",
            text: "请至少选择一项待删除！",
            confirmButtonText: "确定"
        });
        return;
    }
    var ids=arr.map(Customer=>{
        return "ids="+Customer.customerId  //对应该对象的id
    }).join("&");
    console.log(ids);
    $.get("/batchDelcus?"+ids,msg=>{
        var statu = confirm("Are you sure to delete the current data?");
        if(!statu){
            return false;
        }
        toastr.warning(msg);
        $("#roleTb").bootstrapTable("refresh");
    })
}
// ==========================================以下是客户分配====================================================

$("#fenpei").dialog({
    title: "客户资源分配",
    btnBind(){
        var params=$("#fenpei form").serialize();
        $.get(`${ctx}/upStaff`,params)
            .done(msg=>{
                toastr.success(msg);
                $("#roleTb").bootstrapTable("refresh");
                $("#fenpei").dialog("hide");
            });
    }
})
//绑定员工下拉框值
$.get("allYg")
    .done(list=>{
        list.forEach(function (chayg) {
            var opt=$("<option/>");
            opt.val(chayg.empId);
            opt.text(chayg.empName);
            opt.appendTo("#fenpei [name=serviceProxy]");
        })
    })
// 分配状态回显
$.get("cus/hkzygl/list")
    .done(list=>{
        list.forEach(function (khzygl) {
            var opt= $("<option/>");
            opt.val(khzygl.fenpeiid);
            opt.text(khzygl.fenpeizhuangtai);
            opt.appendTo("#fenpei [name=fenpeizt]");
        })
    })
// 处理状态回显
$.get("cus/hkzygl/queryAll")
    .done(list=>{
        list.forEach(function (Kehustart) {
            var opt= $("<option/>");
            opt.val(Kehustart.kehuid);
            opt.text(Kehustart.kehuzhuangtai);
            opt.appendTo("#fenpei [name=status]");
        })
    })
// 处理类型回显
$.get("cus/hkzygl/queryleixing")
    .done(list=>{
        list.forEach(function (Customertype) {
            var opt= $("<option/>");
            opt.val(Customertype.customerTypeId);
            opt.text(Customertype.customerTypeName);
            opt.appendTo("#fenpei [name=type]");
        })
    })
function fenpei() {
    var arr= $("#roleTb").bootstrapTable("getSelections");
            console.log(arr)
    if(arr[0].fenpeistart.fenpeizhuangtai=="已分配"){
        toastr.success("客户已经被分配过了哦！");
        return
    }
    if(arr.length==0) {
        swal({
            type: "error",
            title: "错误操作！",
            text: "请至少选择一项待分配！",
            confirmButtonText: "确定"
        });
        return;
    }
    $("#fenpei [name=customerId]").val(arr[0].customerId);
    $("#fenpei [name=name]").val(arr[0].name);
    $("#fenpei [name=sex]").val(arr[0].sex);
    $("#fenpei [name=type]").val(arr[0].type);
    $("#fenpei [name=status]").val(arr[0].status);
    $("#fenpei [name=fenpeizt]").val(arr[0].assignmentStatus);
    $("#fenpei [name=cellphone]").val(arr[0].cellphone);
    $("#fenpei [name=name]").val(arr[0].name);
    $("#fenpei [name=createTime]").val(arr[0].createTime);
    $("#fenpei").dialog("show");
}